<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<meta name="generator" content="pdoc 0.10.0" />
<title>Euro-Truck-Simulator-2-Lane-Assist.src.translator API documentation</title>
<meta name="description" content="Provides a standard translation interface. All helper functions already use this interface by default …" />
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/ir-black.min.css" crossorigin>
<style>
:root {
--highlight-color: #202;
}
html {
scrollbar-face-color: #646464;
scrollbar-base-color: #646464;
scrollbar-3dlight-color: #646464;
scrollbar-highlight-color: #646464;
scrollbar-track-color: #000;
scrollbar-arrow-color: #000;
scrollbar-shadow-color: #646464;
scrollbar-dark-shadow-color: #646464;
}
::-webkit-scrollbar { width: 14px; height: 3px;}
::-webkit-scrollbar-button {
background-color: #000;
height: 3px;}
::-webkit-scrollbar-track {
background-color: #646464;}
::-webkit-scrollbar-track-piece { background-color: #000;}
::-webkit-scrollbar-thumb { height: 50px; background-color: #666; border-radius: 7px;}
::-webkit-scrollbar-corner { background-color: #646464;}
::-webkit-resizer { background-color: #666;}
.flex {
display: flex !important;
}
body {
line-height: 1.5em;
color: #fff;
background-color: #1e1e1e;
font: 14px/1.5 Helvetica, Arial, sans-serif;
margin: 0;
padding: 0;
}
#content {
padding: 20px;
}
#sidebar {
padding: 30px;
overflow: hidden;
}
#sidebar>*:last-child {
margin-bottom: 2cm;
}
.http-server-breadcrumbs {
font-size: 130%;
margin: 0 0 15px 0;
}
#footer {
font-size: .75em;
padding: 5px 30px;
border-top: 1px solid #fff;
text-align: right;
}
#footer p {
margin: 0 0 0 1em;
display: inline-block;
}
#footer p:last-child {
margin-right: 30px;
}
h1,
h2,
h3,
h4,
h5 {
font-weight: 300;
color: #fff;
}
h1 {
font-size: 2.5em;
line-height: 1.1em;
}
h2 {
font-size: 1.75em;
margin: 1em 0 .50em 0;
}
h3 {
font-size: 1.4em;
margin: 25px 0 10px 0;
}
h4 {
margin: 0;
font-size: 105%;
}
h1:target,
h2:target,
h3:target,
h4:target,
h5:target,
h6:target {
background: #1e1e1e;
padding: 0.2em 0;
}
a {
color: #8fd6fc;
text-decoration: none;
transition: color .3s ease-in-out;
}
a:hover {
color: #00a4fc;
}
.title code {
font-weight: bold;
}
h2[id^="header-"] {
margin-top: 2em;
}
.ident {
color: #f6fc85;
}
strong {
color: #8fd6fc;
}
pre code {
background: transparent;
font-size: .8em;
line-height: 1.4em;
}
code {
background: rgba(255, 255, 255, 0.1);
padding: 1px 4px;
overflow-wrap: break-word;
}
h1 code {
background: transparent
}
pre {
background: transparent;
border: 0;
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
margin: 1em 0;
padding: 1ex;
}
#http-server-module-list {
display: flex;
flex-flow: column;
}
#http-server-module-list div {
display: flex;
}
#http-server-module-list dt {
min-width: 10%;
}
#http-server-module-list p {
margin-top: 0;
}
.toc ul,
#index {
list-style-type: none;
margin: 0;
padding: 0;
}
#index code {
background: transparent;
}
#index h3 {
border-bottom: 1px solid #ddd;
}
#index ul {
padding: 0;
}
#index h4 {
margin-top: .6em;
font-weight: bold;
}
/* Make TOC lists have 2+ columns when viewport is wide enough.
Assuming ~20-character identifiers and ~30% wide sidebar. */
@media (min-width: 200ex) {
#index .two-column {
column-count: 2
}
}
@media (min-width: 300ex) {
#index .two-column {
column-count: 3
}
}
dl {
margin-bottom: 2em;
}
dl dl:last-child {
margin-bottom: 4em;
}
dd {
margin: 0 0 1em 3em;
}
#header-classes+dl>dd {
margin-bottom: 3em;
}
dd dd {
margin-left: 2em;
}
dd p {
margin: 10px 0;
}
.name {
background: #000;
font-weight: bold;
font-size: .85em;
padding: 5px 10px;
display: inline-block;
min-width: 40%;
}
.name:hover {
background: #0b0b0b;
}
dt:target .name {
background: var(--highlight-color);
}
.name>span:first-child {
white-space: nowrap;
}
.name.class>span:nth-child(2) {
margin-left: .4em;
}
.inherited {
color: #999;
border-left: 5px solid #eee;
padding-left: 1em;
}
.inheritance em {
font-style: normal;
font-weight: bold;
}
.pydefname {
color: #f90;
}
/* Docstrings titles, e.g. in numpydoc format */
.desc h2 {
font-weight: 400;
font-size: 1.25em;
}
.desc h3 {
font-size: 1em;
}
.desc dt code {
background: inherit;
/* Don't grey-back parameters */
}
.source summary,
.git-link-div {
color: #666;
text-align: right;
font-weight: 400;
font-size: .8em;
text-transform: uppercase;
}
.source summary>* {
white-space: nowrap;
cursor: pointer;
}
.git-link {
color: inherit;
margin-left: 1em;
}
.source pre {
max-height: 500px;
overflow: auto;
margin: 0;
}
.source pre code {
font-size: 12px;
overflow: visible;
}
.hlist {
list-style: none;
}
.hlist li {
display: inline;
}
.hlist li:after {
content: ',\2002';
}
.hlist li:last-child:after {
content: none;
}
.hlist .hlist {
display: inline;
padding-left: 1em;
}
img {
max-width: 100%;
}
td {
padding: 0 .5em;
}
.admonition {
padding: .1em .5em;
margin-bottom: 1em;
}
.admonition-title {
font-weight: bold;
}
.admonition.note,
.admonition.info,
.admonition.important {
background: #00a;
}
.admonition.todo,
.admonition.versionadded,
.admonition.tip,
.admonition.hint {
background: #050;
}
.admonition.warning,
.admonition.versionchanged,
.admonition.deprecated {
background: #ec0;
}
.admonition.error,
.admonition.danger,
.admonition.caution {
background: #c20010;
}
p {
color: #fff;
}
</style>
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
</head>
<body>
<main>
<article id="content">
<header>
<h1 class="title">Module <code>Euro-Truck-Simulator-2-Lane-Assist.src.translator</code></h1>
</header>
<section id="section-intro">
<p>Provides a standard translation interface. All helper functions already use this interface by default.</p>
<p>Usage:</p>
<pre><code class="language-python">from src.translator import Translate
print(Translate(&quot;Hello world!&quot;))
</code></pre>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">&#34;&#34;&#34;Provides a standard translation interface. All helper functions already use this interface by default.

Usage:
```python
from src.translator import Translate
print(Translate(&#34;Hello world!&#34;))
```&#34;&#34;&#34;
import deep_translator as dt
import src.settings as settings
import src.loading as loading
import src.mainUI as mainUI
from src.logger import print
import json
import os

def GetOSLanguage():
    &#34;&#34;&#34;Will get the current OS language.

    Returns:
        str: 2 letter language code.
    &#34;&#34;&#34;
    if os.name == &#34;nt&#34;:
        import ctypes
        import locale
        from babel import Locale
        windll = ctypes.windll.kernel32
        language = locale.windows_locale[windll.GetUserDefaultUILanguage()]
        language = Locale.parse(language)
        language = language.language
        
        # Override for simplified chinese
        if language == &#34;zh&#34;:
            language = &#34;zh-CN&#34;
            
        return language
    else:
        return os.environ.get(&#34;LANG&#34;).split(&#34;_&#34;)[0]

def LoadSettings():
    &#34;&#34;&#34;Will load the translation settings from the settings file.
    &#34;&#34;&#34;
    global origin
    global dest
    global enableCache
    global cachePath

    # Load Language settings
    origin = settings.GetSettings(&#34;User Interface&#34;, &#34;OriginLanguage&#34;)
    dest = settings.GetSettings(&#34;User Interface&#34;, &#34;DestinationLanguage&#34;)
    if origin == None:
        origin = &#34;en&#34;
        settings.CreateSettings(&#34;User Interface&#34;, &#34;OriginLanguage&#34;, origin)
    if dest == None:
        dest = GetOSLanguage()
        settings.CreateSettings(&#34;User Interface&#34;, &#34;DestinationLanguage&#34;, dest)

    # Load Translation Cache settings
    enableCache = settings.GetSettings(&#34;User Interface&#34;, &#34;EnableTranslationCache&#34;)
    print(enableCache)
    cachePath = settings.GetSettings(&#34;User Interface&#34;, &#34;TranslationCachePath&#34;)
    if enableCache == None:
        enableCache = True
        settings.CreateSettings(&#34;User Interface&#34;, &#34;EnableTranslationCache&#34;, enableCache)
    if cachePath == None:
        cachePath = &#34;assets/translationCache/cache.json&#34;
        settings.CreateSettings(&#34;User Interface&#34;, &#34;TranslationCachePath&#34;, cachePath)

LoadSettings()

translator = None
&#34;&#34;&#34;The translator object. (from deep_translator)&#34;&#34;&#34;
def MakeTranslator(type:str):
    &#34;&#34;&#34;Will create the translator object.

    Args:
        type (str): Translator type. (google)
    &#34;&#34;&#34;
    global origin
    global dest
    global translator
    
    del translator
    translator = None
    
    if type == &#34;google&#34;:
        try:
            translator = dt.GoogleTranslator(source=origin, target=dest)
        except:
            try:
                translator = dt.GoogleTranslator(source=&#34;en&#34;, target=&#34;en&#34;)
            except:
                pass

MakeTranslator(&#34;google&#34;)
AVAILABLE_LANGUAGES = translator.get_supported_languages(as_dict=True)
&#34;&#34;&#34;A dictionary of all available languages.&#34;&#34;&#34;
def FindLanguageFromCode(code:str):
    &#34;&#34;&#34;Get language from code.

    Args:
        code (str): 2 letter language code.

    Returns:
        str: Language name.
    &#34;&#34;&#34;
    for language in AVAILABLE_LANGUAGES:
        if AVAILABLE_LANGUAGES[language] == code:
            return language
    return None

def FindCodeFromLanguage(language:str):
    &#34;&#34;&#34;Get 2 letter language code from language.

    Args:
        language (str): Language name.

    Returns:
        str: 2 letter language code.
    &#34;&#34;&#34;
    for lang in AVAILABLE_LANGUAGES:
        if lang == language.lower():
            return AVAILABLE_LANGUAGES[lang]
    return None

def CheckCache(text:str, language:str=None):
    &#34;&#34;&#34;Will check the translation cache for a specific text.

    Args:
        text (str): Text to check.
        language (str, optional): Language to check. If None will get from dest. Defaults to None.

    Returns:
        str / bool: Either the translation or False.
    &#34;&#34;&#34;
    # Code for checking the manual cache
    if language == None:
        language = dest
        
    manualPath = f&#34;assets/manualTranslations/{origin}-{language}.json&#34;
    try:
        file = open(manualPath, &#34;r&#34;)
        cache = json.load(file)
        file.close()
        
        try:
            return cache[text]
        except KeyError:
            pass
    except:
        pass
    
    # Code for checking the automatic cache
    try:
        file = open(cachePath, &#34;r&#34;)
    except:
        try:
            os.mkdir(&#34;assets/translationCache&#34;)
        except: pass
        file = open(cachePath, &#34;w&#34;)
        file.write(&#34;{}&#34;)
        file.close()
        return False
    
    cache = json.load(file)
    file.close()
    try:
        if text in cache[language]:
            return cache[language][text]
        else:
            return False
    except KeyError:
        return False

def ReturnCacheForLanguage(language:str=None):
    &#34;&#34;&#34;Will return the entire translation cache for a single language.&#34;&#34;&#34;
    file = open(cachePath, &#34;r&#34;)
    cache = json.load(file)
    file.close()
    
    if language == None:
        language = dest
        
    try:
        return cache[language]
    except KeyError:
        return {}

def AddToCache(text:str, translation:str, language:str=None):
    &#34;&#34;&#34;Will add a translation to the cache.

    Args:
        text (str): Original text.
        translation (str): Translation to add.
        language (str, optional): Language to associate. Defaults to None.
    &#34;&#34;&#34;
    file = open(cachePath, &#34;r&#34;)
    cache = json.load(file)
    file.close()
    
    if language == None:
        language = dest
    
    try:
        cache[language][text] = translation
    except KeyError:
        cache[language] = {}
        cache[language][text] = translation
    
    file = open(cachePath, &#34;w&#34;)
    file.truncate(0)
    json.dump(cache, file, indent=4)
    file.close()    

def Translate(text:str, originalLanguage:str=None, destinationLanguage:str=None):
    &#34;&#34;&#34;Will translate a given text.

    Args:
        text (str): The text to translate.
        originalLanguage (str, optional): The original language, if None will infer automatically. Defaults to None.
        destinationLanguage (str, optional): The destination language, if None will get from settings. Defaults to None.

    Returns:
        str: The translated text.
    &#34;&#34;&#34;
    global origin
    global dest
    
    
    if originalLanguage == None:
        originalLanguage = origin
    else:
        origin = originalLanguage
        MakeTranslator(&#34;google&#34;)
        
    if destinationLanguage == None:
        destinationLanguage = dest
    else:
        dest = destinationLanguage
        MakeTranslator(&#34;google&#34;)
        
    if originalLanguage == destinationLanguage:
        return text
    
    if translator == None:
        return text
    
    def TranslateText(text):
        try:
            if enableCache:
                cache = CheckCache(text)
                if cache != False:
                    return cache
                else:
                    mainUI.fps.set(f&#34;TRANSLATING\tTRANSLATING\tTRANSLATING\tTRANSLATING\tTRANSLATING\tTRANSLATING\tTRANSLATING&#34;)
                    mainUI.UpdateTitle(extraText=&#34;TRANSLATING...&#34;)
                    mainUI.root.update()

                    translation = translator.translate(text, max_chars=20000)
                    AddToCache(text, translation)
                    mainUI.UpdateTitle()
                    return translation
            else:
                mainUI.fps.set(f&#34;TRANSLATING\tTRANSLATING\tTRANSLATING\tTRANSLATING\tTRANSLATING\tTRANSLATING\tTRANSLATING&#34;)
                mainUI.UpdateTitle(extraText=&#34;TRANSLATING...&#34;)
                mainUI.root.update()

                translation = translator.translate(text)
                mainUI.UpdateTitle()
                return translation
        except:
            return text # Return the original text if the translation fails
    
    # Check if the text is an array of strings
    if type(text) == list:
        translatedText = []
        for string in text:
            translatedText.append(TranslateText(string))
            
        return translatedText
    else:
        return TranslateText(text)
    
def CreateManualTranslationFile():
    &#34;&#34;&#34;Will create a manual translation file.
    &#34;&#34;&#34;
    global origin
    global dest
    
    if origin == dest:
        return
    
    from tkinter import messagebox
    
    try:
        os.mkdir(&#34;assets/manualTranslations&#34;)
    except: pass
    
    file = open(f&#34;assets/manualTranslations/{origin}-{dest}.json&#34;, &#34;w&#34;)
    # Copy the current translation for the languages
    cache = ReturnCacheForLanguage(dest)
    json.dump(cache, file, indent=4)
    file.close()   
    
    messagebox.showinfo(&#34;DeepTranslator&#34;, f&#34;Manual translation file created in &#39;assets/manualTranslations/{origin}-{dest}.json&#39;&#34;)</code></pre>
</details>
</section>
<section>
</section>
<section>
<h2 class="section-title" id="header-variables">Global variables</h2>
<dl>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.src.translator.AVAILABLE_LANGUAGES"><code class="name">var <span class="ident">AVAILABLE_LANGUAGES</span></code></dt>
<dd>
<div class="desc"><p>A dictionary of all available languages.</p></div>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.src.translator.translator"><code class="name">var <span class="ident">translator</span></code></dt>
<dd>
<div class="desc"><p>The translator object. (from deep_translator)</p></div>
</dd>
</dl>
</section>
<section>
<h2 class="section-title" id="header-functions">Functions</h2>
<dl>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.src.translator.AddToCache"><code class="name flex">
<span>def <span class="ident">AddToCache</span></span>(<span>text: str, translation: str, language: str = None)</span>
</code></dt>
<dd>
<div class="desc"><p>Will add a translation to the cache.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>text</code></strong> :&ensp;<code>str</code></dt>
<dd>Original text.</dd>
<dt><strong><code>translation</code></strong> :&ensp;<code>str</code></dt>
<dd>Translation to add.</dd>
<dt><strong><code>language</code></strong> :&ensp;<code>str</code>, optional</dt>
<dd>Language to associate. Defaults to None.</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def AddToCache(text:str, translation:str, language:str=None):
    &#34;&#34;&#34;Will add a translation to the cache.

    Args:
        text (str): Original text.
        translation (str): Translation to add.
        language (str, optional): Language to associate. Defaults to None.
    &#34;&#34;&#34;
    file = open(cachePath, &#34;r&#34;)
    cache = json.load(file)
    file.close()
    
    if language == None:
        language = dest
    
    try:
        cache[language][text] = translation
    except KeyError:
        cache[language] = {}
        cache[language][text] = translation
    
    file = open(cachePath, &#34;w&#34;)
    file.truncate(0)
    json.dump(cache, file, indent=4)
    file.close()    </code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.src.translator.CheckCache"><code class="name flex">
<span>def <span class="ident">CheckCache</span></span>(<span>text: str, language: str = None)</span>
</code></dt>
<dd>
<div class="desc"><p>Will check the translation cache for a specific text.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>text</code></strong> :&ensp;<code>str</code></dt>
<dd>Text to check.</dd>
<dt><strong><code>language</code></strong> :&ensp;<code>str</code>, optional</dt>
<dd>Language to check. If None will get from dest. Defaults to None.</dd>
</dl>
<h2 id="returns">Returns</h2>
<p>str / bool: Either the translation or False.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def CheckCache(text:str, language:str=None):
    &#34;&#34;&#34;Will check the translation cache for a specific text.

    Args:
        text (str): Text to check.
        language (str, optional): Language to check. If None will get from dest. Defaults to None.

    Returns:
        str / bool: Either the translation or False.
    &#34;&#34;&#34;
    # Code for checking the manual cache
    if language == None:
        language = dest
        
    manualPath = f&#34;assets/manualTranslations/{origin}-{language}.json&#34;
    try:
        file = open(manualPath, &#34;r&#34;)
        cache = json.load(file)
        file.close()
        
        try:
            return cache[text]
        except KeyError:
            pass
    except:
        pass
    
    # Code for checking the automatic cache
    try:
        file = open(cachePath, &#34;r&#34;)
    except:
        try:
            os.mkdir(&#34;assets/translationCache&#34;)
        except: pass
        file = open(cachePath, &#34;w&#34;)
        file.write(&#34;{}&#34;)
        file.close()
        return False
    
    cache = json.load(file)
    file.close()
    try:
        if text in cache[language]:
            return cache[language][text]
        else:
            return False
    except KeyError:
        return False</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.src.translator.CreateManualTranslationFile"><code class="name flex">
<span>def <span class="ident">CreateManualTranslationFile</span></span>(<span>)</span>
</code></dt>
<dd>
<div class="desc"><p>Will create a manual translation file.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def CreateManualTranslationFile():
    &#34;&#34;&#34;Will create a manual translation file.
    &#34;&#34;&#34;
    global origin
    global dest
    
    if origin == dest:
        return
    
    from tkinter import messagebox
    
    try:
        os.mkdir(&#34;assets/manualTranslations&#34;)
    except: pass
    
    file = open(f&#34;assets/manualTranslations/{origin}-{dest}.json&#34;, &#34;w&#34;)
    # Copy the current translation for the languages
    cache = ReturnCacheForLanguage(dest)
    json.dump(cache, file, indent=4)
    file.close()   
    
    messagebox.showinfo(&#34;DeepTranslator&#34;, f&#34;Manual translation file created in &#39;assets/manualTranslations/{origin}-{dest}.json&#39;&#34;)</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.src.translator.FindCodeFromLanguage"><code class="name flex">
<span>def <span class="ident">FindCodeFromLanguage</span></span>(<span>language: str)</span>
</code></dt>
<dd>
<div class="desc"><p>Get 2 letter language code from language.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>language</code></strong> :&ensp;<code>str</code></dt>
<dd>Language name.</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>str</code></dt>
<dd>2 letter language code.</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def FindCodeFromLanguage(language:str):
    &#34;&#34;&#34;Get 2 letter language code from language.

    Args:
        language (str): Language name.

    Returns:
        str: 2 letter language code.
    &#34;&#34;&#34;
    for lang in AVAILABLE_LANGUAGES:
        if lang == language.lower():
            return AVAILABLE_LANGUAGES[lang]
    return None</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.src.translator.FindLanguageFromCode"><code class="name flex">
<span>def <span class="ident">FindLanguageFromCode</span></span>(<span>code: str)</span>
</code></dt>
<dd>
<div class="desc"><p>Get language from code.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>code</code></strong> :&ensp;<code>str</code></dt>
<dd>2 letter language code.</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>str</code></dt>
<dd>Language name.</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def FindLanguageFromCode(code:str):
    &#34;&#34;&#34;Get language from code.

    Args:
        code (str): 2 letter language code.

    Returns:
        str: Language name.
    &#34;&#34;&#34;
    for language in AVAILABLE_LANGUAGES:
        if AVAILABLE_LANGUAGES[language] == code:
            return language
    return None</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.src.translator.GetOSLanguage"><code class="name flex">
<span>def <span class="ident">GetOSLanguage</span></span>(<span>)</span>
</code></dt>
<dd>
<div class="desc"><p>Will get the current OS language.</p>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>str</code></dt>
<dd>2 letter language code.</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def GetOSLanguage():
    &#34;&#34;&#34;Will get the current OS language.

    Returns:
        str: 2 letter language code.
    &#34;&#34;&#34;
    if os.name == &#34;nt&#34;:
        import ctypes
        import locale
        from babel import Locale
        windll = ctypes.windll.kernel32
        language = locale.windows_locale[windll.GetUserDefaultUILanguage()]
        language = Locale.parse(language)
        language = language.language
        
        # Override for simplified chinese
        if language == &#34;zh&#34;:
            language = &#34;zh-CN&#34;
            
        return language
    else:
        return os.environ.get(&#34;LANG&#34;).split(&#34;_&#34;)[0]</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.src.translator.LoadSettings"><code class="name flex">
<span>def <span class="ident">LoadSettings</span></span>(<span>)</span>
</code></dt>
<dd>
<div class="desc"><p>Will load the translation settings from the settings file.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def LoadSettings():
    &#34;&#34;&#34;Will load the translation settings from the settings file.
    &#34;&#34;&#34;
    global origin
    global dest
    global enableCache
    global cachePath

    # Load Language settings
    origin = settings.GetSettings(&#34;User Interface&#34;, &#34;OriginLanguage&#34;)
    dest = settings.GetSettings(&#34;User Interface&#34;, &#34;DestinationLanguage&#34;)
    if origin == None:
        origin = &#34;en&#34;
        settings.CreateSettings(&#34;User Interface&#34;, &#34;OriginLanguage&#34;, origin)
    if dest == None:
        dest = GetOSLanguage()
        settings.CreateSettings(&#34;User Interface&#34;, &#34;DestinationLanguage&#34;, dest)

    # Load Translation Cache settings
    enableCache = settings.GetSettings(&#34;User Interface&#34;, &#34;EnableTranslationCache&#34;)
    print(enableCache)
    cachePath = settings.GetSettings(&#34;User Interface&#34;, &#34;TranslationCachePath&#34;)
    if enableCache == None:
        enableCache = True
        settings.CreateSettings(&#34;User Interface&#34;, &#34;EnableTranslationCache&#34;, enableCache)
    if cachePath == None:
        cachePath = &#34;assets/translationCache/cache.json&#34;
        settings.CreateSettings(&#34;User Interface&#34;, &#34;TranslationCachePath&#34;, cachePath)</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.src.translator.MakeTranslator"><code class="name flex">
<span>def <span class="ident">MakeTranslator</span></span>(<span>type: str)</span>
</code></dt>
<dd>
<div class="desc"><p>Will create the translator object.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>type</code></strong> :&ensp;<code>str</code></dt>
<dd>Translator type. (google)</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def MakeTranslator(type:str):
    &#34;&#34;&#34;Will create the translator object.

    Args:
        type (str): Translator type. (google)
    &#34;&#34;&#34;
    global origin
    global dest
    global translator
    
    del translator
    translator = None
    
    if type == &#34;google&#34;:
        try:
            translator = dt.GoogleTranslator(source=origin, target=dest)
        except:
            try:
                translator = dt.GoogleTranslator(source=&#34;en&#34;, target=&#34;en&#34;)
            except:
                pass</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.src.translator.ReturnCacheForLanguage"><code class="name flex">
<span>def <span class="ident">ReturnCacheForLanguage</span></span>(<span>language: str = None)</span>
</code></dt>
<dd>
<div class="desc"><p>Will return the entire translation cache for a single language.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def ReturnCacheForLanguage(language:str=None):
    &#34;&#34;&#34;Will return the entire translation cache for a single language.&#34;&#34;&#34;
    file = open(cachePath, &#34;r&#34;)
    cache = json.load(file)
    file.close()
    
    if language == None:
        language = dest
        
    try:
        return cache[language]
    except KeyError:
        return {}</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.src.translator.Translate"><code class="name flex">
<span>def <span class="ident">Translate</span></span>(<span>text: str, originalLanguage: str = None, destinationLanguage: str = None)</span>
</code></dt>
<dd>
<div class="desc"><p>Will translate a given text.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>text</code></strong> :&ensp;<code>str</code></dt>
<dd>The text to translate.</dd>
<dt><strong><code>originalLanguage</code></strong> :&ensp;<code>str</code>, optional</dt>
<dd>The original language, if None will infer automatically. Defaults to None.</dd>
<dt><strong><code>destinationLanguage</code></strong> :&ensp;<code>str</code>, optional</dt>
<dd>The destination language, if None will get from settings. Defaults to None.</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>str</code></dt>
<dd>The translated text.</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def Translate(text:str, originalLanguage:str=None, destinationLanguage:str=None):
    &#34;&#34;&#34;Will translate a given text.

    Args:
        text (str): The text to translate.
        originalLanguage (str, optional): The original language, if None will infer automatically. Defaults to None.
        destinationLanguage (str, optional): The destination language, if None will get from settings. Defaults to None.

    Returns:
        str: The translated text.
    &#34;&#34;&#34;
    global origin
    global dest
    
    
    if originalLanguage == None:
        originalLanguage = origin
    else:
        origin = originalLanguage
        MakeTranslator(&#34;google&#34;)
        
    if destinationLanguage == None:
        destinationLanguage = dest
    else:
        dest = destinationLanguage
        MakeTranslator(&#34;google&#34;)
        
    if originalLanguage == destinationLanguage:
        return text
    
    if translator == None:
        return text
    
    def TranslateText(text):
        try:
            if enableCache:
                cache = CheckCache(text)
                if cache != False:
                    return cache
                else:
                    mainUI.fps.set(f&#34;TRANSLATING\tTRANSLATING\tTRANSLATING\tTRANSLATING\tTRANSLATING\tTRANSLATING\tTRANSLATING&#34;)
                    mainUI.UpdateTitle(extraText=&#34;TRANSLATING...&#34;)
                    mainUI.root.update()

                    translation = translator.translate(text, max_chars=20000)
                    AddToCache(text, translation)
                    mainUI.UpdateTitle()
                    return translation
            else:
                mainUI.fps.set(f&#34;TRANSLATING\tTRANSLATING\tTRANSLATING\tTRANSLATING\tTRANSLATING\tTRANSLATING\tTRANSLATING&#34;)
                mainUI.UpdateTitle(extraText=&#34;TRANSLATING...&#34;)
                mainUI.root.update()

                translation = translator.translate(text)
                mainUI.UpdateTitle()
                return translation
        except:
            return text # Return the original text if the translation fails
    
    # Check if the text is an array of strings
    if type(text) == list:
        translatedText = []
        for string in text:
            translatedText.append(TranslateText(string))
            
        return translatedText
    else:
        return TranslateText(text)</code></pre>
</details>
</dd>
</dl>
</section>
<section>
</section>
</article>
<nav id="sidebar">
<h1>Index</h1>
<div class="toc">
<ul></ul>
</div>
<ul id="index">
<li><h3>Super-module</h3>
<ul>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.src" href="index.html">Euro-Truck-Simulator-2-Lane-Assist.src</a></code></li>
</ul>
</li>
<li><h3><a href="#header-variables">Global variables</a></h3>
<ul class="">
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.src.translator.AVAILABLE_LANGUAGES" href="#Euro-Truck-Simulator-2-Lane-Assist.src.translator.AVAILABLE_LANGUAGES">AVAILABLE_LANGUAGES</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.src.translator.translator" href="#Euro-Truck-Simulator-2-Lane-Assist.src.translator.translator">translator</a></code></li>
</ul>
</li>
<li><h3><a href="#header-functions">Functions</a></h3>
<ul class="">
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.src.translator.AddToCache" href="#Euro-Truck-Simulator-2-Lane-Assist.src.translator.AddToCache">AddToCache</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.src.translator.CheckCache" href="#Euro-Truck-Simulator-2-Lane-Assist.src.translator.CheckCache">CheckCache</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.src.translator.CreateManualTranslationFile" href="#Euro-Truck-Simulator-2-Lane-Assist.src.translator.CreateManualTranslationFile">CreateManualTranslationFile</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.src.translator.FindCodeFromLanguage" href="#Euro-Truck-Simulator-2-Lane-Assist.src.translator.FindCodeFromLanguage">FindCodeFromLanguage</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.src.translator.FindLanguageFromCode" href="#Euro-Truck-Simulator-2-Lane-Assist.src.translator.FindLanguageFromCode">FindLanguageFromCode</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.src.translator.GetOSLanguage" href="#Euro-Truck-Simulator-2-Lane-Assist.src.translator.GetOSLanguage">GetOSLanguage</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.src.translator.LoadSettings" href="#Euro-Truck-Simulator-2-Lane-Assist.src.translator.LoadSettings">LoadSettings</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.src.translator.MakeTranslator" href="#Euro-Truck-Simulator-2-Lane-Assist.src.translator.MakeTranslator">MakeTranslator</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.src.translator.ReturnCacheForLanguage" href="#Euro-Truck-Simulator-2-Lane-Assist.src.translator.ReturnCacheForLanguage">ReturnCacheForLanguage</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.src.translator.Translate" href="#Euro-Truck-Simulator-2-Lane-Assist.src.translator.Translate">Translate</a></code></li>
</ul>
</li>
</ul>
</nav>
</main>
<footer id="footer">
<p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.10.0</a>.</p>
</footer>
</body>
</html>